package com.tsign.module.lib.core.base;

import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;

import javax.inject.Inject;

/**
 * @author xhj
 * @date 2018/7/3
 */
public abstract class BaseAty<T extends BasePresenter> extends FragmentActivity implements BaseContract.BaseView {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(this.getLayoutId());
        try {
            mPresenter = createPresenter();
            this.initViews();
            this.initData();
            this.initListeners();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * presenter
     */
    public T mPresenter;

    /**
     * 在此方法里面获取layoutId
     *
     * @return
     */
    public abstract int getLayoutId();

    /**
     * 初始化View
     */
    public abstract void initViews();

    /**
     * 初始化数据
     */
    public abstract void initData();

    /**
     * 初始化接口
     */
    public abstract void initListeners();

    /**
     * 用于创建Presenter和判断是否使用MVP模式(由子类实现)\
     *
     * @return
     */
    public abstract T createPresenter();

    @Override
    public void showToastMessage(String message) {
        runOnUiThread(() -> Toast.makeText(this, message, Toast.LENGTH_SHORT).show());
    }
}
